<div class="hbox hbox-auto-xs hbox-auto-sm" ng-init="
    app.settings.asideFolded = false;
    app.settings.asideDock = false;">
    <!-- main -->
    <div class="col">
        <!-- main header -->
        <div class="bg-light lter b-b wrapper-md">
            <div class="row">
                <div class="col-sm-6 col-xs-12" ng-controller="ansibleVersionCtrl">
                    <h1 class="m-n font-thin h3 text-black">Ansible Task
                        <button ng-click="ansibleVersion()"
                                class="btn btn-xs"
                                style="margin-left: 5px; background-color: #00a8f3; color: white;">
                            <span class="icon icon-info"></span> Version
                        </button>
                    </h1>
                    <small class="text-muted">服务器批量运维</small>
                </div>
            </div>
        </div>
        <!-- / main header -->
        <div class="wrapper-md">
            <!-- toaster directive -->
            <toaster-container
                    toaster-options="{'position-class': 'toast-top-right', 'close-button':true}"></toaster-container>
            <!-- / toaster directive -->

            <uib-tabset>
                <uib-tab index="0" heading="批量指令">
                    <div class="panel panel-default" ng-controller="taskCmdCtrl">
                        <div class="panel-body">


                            <div class="form-group col-md-12">
                                <div class="col-md-6">
                                    <label class="col-lg-2 control-label" style="margin-top: 5px;"><span
                                            style="color: #ec2121;">*</span>服务器组</label>
                                    <div class="col-lg-5">
                                        <ui-select ng-model="nowServerGroup.selected" theme="bootstrap"
                                                   ng-change="changeServerGroup()">
                                            <ui-select-match placeholder="搜索服务器组名称......">{{$select.selected.name}}
                                            </ui-select-match>
                                            <ui-select-choices refresh="queryServerGroup($select.search)"
                                                               refresh-dalay="0"
                                                               repeat="item in serverGroupList | filter: $select.search">
                                                <div ng-bind-html="item.name | highlight: $select.search"></div>
                                            </ui-select-choices>
                                        </ui-select>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group col-md-12">
                                <div class="col-md-6">
                                    <label class="col-lg-2 control-label" style="margin-top: 5px;">
                                        <span style="color: #ec2121;">*</span>执行指令</label>
                                    <div class="col-lg-9">
                                        <input type="text" class="form-control" placeholder="执行指令"
                                               ng-model="cmd">
                                    </div>
                                </div>

                                <button class="btn btn-info" ng-click="doCmd()" ng-disabled="btnDoCmd">
                                    <i class="fa fa-play"></i>执行
                                </button>
                            </div>

                            <div style="font-size:1em;">&nbsp;</div>

                            <!--服务器列表-->
                            <form class="form-horizontal col-md-12" style="box-shadow: 0 0 5px #ddd;padding: 10px;">
                                <div ng-include="'tpl/modal/servertask/servertask_serverlist.html'"></div>
                            </form>

                            <!--任务详情-->
                            <form class="form-horizontal col-md-12" style="box-shadow: 0 0 5px #ddd;padding: 10px;margin-top: 10px;">
                                <div ng-include="'tpl/modal/servertask/servertask_result.html'"></div>
                            </form>

                            <div style="font-size:0.5em;">&nbsp;</div>

                            <div class="form-group">
                                <div ng-if="alert.type != ''">
                                    <div uib-alert ng-class="'alert-' + alert.type" close="closeAlert()">{{alert.msg}}
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </uib-tab>
                <uib-tab index="1" heading="批量脚本">
                    <div class="panel panel-default" ng-controller="taskScriptCtrl">
                        <div class="panel-body">
                            <div class="form-group col-md-12">

                                    <label class="col-lg-1 control-label" style="margin-top: 5px;"><span
                                            style="color: #ec2121;">*</span>服务器组</label>
                                    <div class="col-lg-3">
                                        <ui-select ng-model="nowServerGroup.selected" theme="bootstrap"
                                                   ng-change="changeServerGroup()">
                                            <ui-select-match placeholder="搜索服务器组名称......">{{$select.selected.name}}
                                            </ui-select-match>
                                            <ui-select-choices refresh="queryServerGroup($select.search)"
                                                               refresh-dalay="0"
                                                               repeat="item in serverGroupList | filter: $select.search">
                                                <div ng-bind-html="item.name | highlight: $select.search"></div>
                                            </ui-select-choices>
                                        </ui-select>
                                    </div>

                            </div>

                            <div class="form-group col-md-12">

                                    <label class="col-lg-1 control-label" style="margin-top: 5px;"><span
                                            style="color: #ec2121;">*</span>选择脚本</label>
                                    <div class="col-lg-3">
                                        <!--ng-change="changeServerGroup()"-->
                                        <ui-select ng-model="nowTaskScript.selected" theme="bootstrap">
                                            <ui-select-match placeholder="搜索Script名称......">
                                                {{$select.selected.scriptName }}
                                            </ui-select-match>
                                            <ui-select-choices refresh="queryTaskScript($select.search)"
                                                               refresh-dalay="0"
                                                               repeat="item in taskScriptList | filter: $select.search">
                                                <div ng-bind-html="item.scriptName | highlight: $select.search"></div>
                                            </ui-select-choices>
                                        </ui-select>
                                    </div>

                                    <div class="col-lg-1">
                                        <button ng-click="viewScript()" class="btn"
                                                style="margin-left: 5px; background-color: #00a8f3; color: white;">
                                            <span class="glyphicon glyphicon-search"></span>查看
                                        </button>
                                    </div>

                                    <label class="col-lg-1 control-label" style="margin-top: 5px;">脚本参数</label>
                                    <div class="col-lg-4">
                                        <input type="text" class="form-control" placeholder="script参数"
                                               ng-model="params">
                                    </div>

                                    <div class="col-lg-1">
                                        <button class="btn"
                                                style="margin-left: 5px; background-color: #c9302c; color: white;"
                                                ng-click="doScript()" ng-disabled="btnDoScript">
                                            <i class="fa fa-play"></i>执行
                                        </button>
                                    </div>



                            </div>

                            <div style="font-size:1em;">&nbsp;</div>


                            <form class="form-horizontal col-md-12" style="box-shadow: 0 0 5px #ddd;padding: 10px;">
                                <div ng-include="'tpl/modal/servertask/servertask_serverlist.html'"></div>
                            </form>

                            <!--任务详情-->
                            <form class="form-horizontal col-md-12" style="box-shadow: 0 0 5px #ddd;padding: 10px;margin-top: 10px;">
                                <div ng-include="'tpl/modal/servertask/servertask_result.html'"></div>
                            </form>

                            <div class="form-group">
                                <div ng-if="alert.type != ''">
                                    <div uib-alert ng-class="'alert-' + alert.type" close="closeAlert()">{{alert.msg}}
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </uib-tab>
                <uib-tab index="2" heading="PLAYBOOK" ng-show="false">
                    <div class="panel panel-default" ng-controller="taskPlaybookCtrl">
                        <div class="panel-body">
                            <div class="form-group col-md-12">
                                <div class="col-md-6">
                                    <label class="col-lg-2 control-label" style="margin-top: 5px;"><span
                                            style="color: #ec2121;">*</span>服务器组</label>
                                    <div class="col-lg-5">
                                        <ui-select ng-model="nowServerGroup.selected" theme="bootstrap">
                                            <ui-select-match placeholder="搜索服务器组名称......">{{$select.selected.name}}
                                            </ui-select-match>
                                            <ui-select-choices refresh="queryServerGroup($select.search)"
                                                               refresh-dalay="0"
                                                               repeat="item in serverGroupList | filter: $select.search">
                                                <div ng-bind-html="item.name | highlight: $select.search"></div>
                                            </ui-select-choices>
                                        </ui-select>
                                    </div>
                                    <div class="col-lg-2">
                                        <button ng-click="addServerGroup()" class="btn btn-xs"
                                                style="margin-top: 5px; background-color: limegreen; color: white;"
                                                uib-popover-html="'添加'" popover-trigger="'mouseenter'">
                                            <span class="glyphicon glyphicon-plus"></span>添加
                                        </button>
                                    </div>
                                </div>

                            </div>

                            <div style="font-size:1em;">&nbsp;</div>

                            <div class="panel"
                                 style="border-color:#c9302c;color:#31708f;background-color:white; box-shadow: 0 0 5px #ddd;padding: 10px;">
                                <div class="panel-heading" style="background-color: #ef2929; color:white;"><b>服务器组列表</b>
                                </div>
                                <table class="table" style="margin-top: 5px;">
                                    <thead>
                                    <tr>
                                        <td class="col-md-1">选择</td>
                                        <td class="col-md-2">服务器组</td>
                                        <td class="col-md-3">HostPattern(用于`hosts`变量)</td>
                                        <td class="col-md-6">服务器列表</td>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr ng-repeat="serverGroup in playbookServerGroupList">
                                        <td>
                                            <input type="checkbox" ng-model="serverGroup.choose">
                                        </td>
                                        <td>
                                            <span class="label"
                                                  style="margin-top: 5px; background-color: #00a8f3; color: white;">{{serverGroup.name}}</span>
                                        </td>
                                        <td>
                                            <select class="form-control"
                                                    ng-model="serverGroup.hostPatternSelected"
                                                    ng-options="hp as hp.hostPattern for hp in serverGroup.hostPattern"
                                                    required>
                                                <option value="">--请选择--</option>
                                            </select>
                                        </td>
                                        <td>
                                            <div class="col-md-6"
                                                 ng-repeat="server in serverGroup.hostPatternSelected.servers">
                                                <b style="margin-left: 5px; color: #286090">
                                                    {{server.serverName}}-{{server.serialNumber}}({{server.insideIp}})</b>
                                            </div>
                                        </td>
                                    </tr>
                                    </tbody>
                                    <tfoot>
                                    </tfoot>
                                </table>
                                <!--<div class="panel-footer">Panel footer</div>-->
                            </div>


                            <div class="form-group col-md-12">


                                <div class="col-md-4">
                                    <label class="col-lg-2 control-label" style="margin-top: 5px;"><span
                                            style="color: #ec2121;">*</span>Playbook</label>
                                    <div class="col-lg-8">
                                        <!--ng-change="changeServerGroup()"-->
                                        <ui-select ng-model="nowTaskScript.selected" theme="bootstrap">
                                            <ui-select-match placeholder="搜索Playbook名称......">
                                                {{$select.selected.scriptName }}
                                            </ui-select-match>
                                            <ui-select-choices refresh="queryTaskScript($select.search)"
                                                               refresh-dalay="0"
                                                               repeat="item in taskScriptList | filter: $select.search">
                                                <div ng-bind-html="item.scriptName | highlight: $select.search"></div>
                                            </ui-select-choices>
                                        </ui-select>
                                    </div>

                                    <div class="col-lg-2">
                                        <button ng-click="viewScript()"
                                                class="btn"
                                                style="margin-left: 5px; background-color: #00a8f3; color: white;">
                                            <span class="glyphicon glyphicon-search"></span>查看
                                        </button>
                                    </div>
                                </div>


                                <div class="col-md-6">
                                    <label class="col-lg-1 control-label" style="margin-top: 5px;">参数</label>
                                    <div class="col-lg-11">
                                        <input type="text" class="form-control" placeholder="script参数"
                                               ng-model="extraVars">
                                    </div>
                                </div>

                                <div class="col-md-2">
                                    <button class="btn"
                                            style="background-color: #c9302c; color: white;"
                                            ng-click="doPlaybook()" ng-disabled="btnDoScript">
                                        <i class="fa fa-play"></i>执行
                                    </button>
                                </div>
                            </div>


                            <div style="font-size:0.5em;">&nbsp;</div>
                            <div class="panel"
                                 style="border-color:#20a03f;color:#31708f;background-color:white; box-shadow: 0 0 5px #ddd;padding: 10px;">
                                <div class="panel-heading" style="background-color:  #2ed556; color:white;"><b>执行结果</b>
                                    <span class="label" style="background-color: #2b669a"
                                          ng-show="taskPlaybook.complete == false">
                                        <i class="fa fa-spin fa-spinner"></i><b>指令执行中...</b>
                                    </span>
                                </div>
                                <div class="form-group">
                                    <form class="form-inline" role="form" ng-if="taskPlaybook.complete">
                                        <table class="table" style="margin-top: 5px;">
                                            <tbody>
                                            <tr ng-repeat="host in taskPlaybook.taskHostList">
                                                <td class="col-md-12"
                                                    ng-show="host.closed ==null || host.closed ==false">
                                                    <div class="panel-heading" style="background-color: #2e6da4">
                                                        <span class="label label-info">{{host.hostPattern}}</span>
                                                        <button ng-click="closeTaskHost(host.id)"
                                                                class="btn btn-xs pull-right"
                                                                style="margin-left: 20px; background-color: #ff8700; color: white;">
                                                            <span class="glyphicon glyphicon-remove"></span>关闭
                                                        </button>
                                                    </div>
                                                    <div hljs hljs-source="host.playbookLogVO.playbookLog"></div>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>

                                    </form>
                                </div>
                            </div>
                            <div class="form-group">
                                <div ng-if="alert.type != ''">
                                    <div uib-alert ng-class="'alert-' + alert.type" close="closeAlert()">{{alert.msg}}
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </uib-tab>
                <uib-tab index="3" heading="任务查询">
                    <div class="panel panel-default" ng-controller="serverTaskCtrl">
                        <div class="panel-body">
                            <form class="form-inline" role="form">
                                <div class="form-group">
                                    <div class="input-group">
                                        <span class="input-group-addon">命令</span>
                                        <input type="text" class="form-control" ng-model="queryCmd" placeholder="执行的指令">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <button type="button" class="btn btn-info" ng-click="doQuery()"><span
                                            class="glyphicon glyphicon-search"></span>搜索
                                    </button>
                                </div>
                            </form>

                            <div class="panel panel-default" style="margin-top: 5px;;">
                                <div class="panel-body">
                                    <div>
                                        <table class="table table-hover table-bordered table-striped">
                                            <thead>
                                            <tr>
                                                <td>Task详情</td>
                                                <td>Cmd/Script</td>
                                                <td>创建时间</td>
                                                <td>操作</td>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr ng-repeat="item in pageData">
                                                <td>
                                                    <b style="color: #1e983b"
                                                       ng-if="item.ansibleTaskDO.finalized == true">执行完成</b>
                                                    <b style="color: #b92c28"
                                                       ng-if="item.ansibleTaskDO.finalized == false">正在执行</b>
                                                    <b class="pull-right">执行状态</b>
                                                    </br>
                                                    <b style="color: #286090">{{item.ansibleTaskDO.serverCnt}}</b>
                                                    <b class="pull-right">服务器数量</b>
                                                    <!--</br>-->
                                                    <!--<b style="color: #1e983b" ng-if="item.ansibleTaskDO.taskType == 0">Cmd</b>-->
                                                    <!--<b style="color: #b92c28" ng-if="item.ansibleTaskDO.taskType== 1">Script</b>-->
                                                    <!--<b class="pull-right">Task类型</b>-->
                                                    </br>
                                                    <b style="color: #286090">{{item.ansibleTaskDO.userName}}</b>
                                                    <b class="pull-right">用户</b>
                                                </td>
                                                <td>
                                                    <b style="color: #286090">{{item.ansibleTaskDO.cmd}}</b>
                                                </td>
                                                <td>{{(item.ansibleTaskDO.gmtModify == null ||
                                                    item.ansibleTaskDO.gmtModify == '') ? item.ansibleTaskDO.gmtCreate
                                                    : item.ansibleTaskDO.gmtModify}}
                                                </td>
                                                <td>
                                                    <button ng-click="viewScript(item)"
                                                            ng-show="item.ansibleTaskDO.taskType == 1"
                                                            class="btn btn-xs"
                                                            style="margin-left: 5px; background-color: #00af00 ;color: white;">
                                                        <span class="glyphicon glyphicon-search"></span>Script
                                                    </button>

                                                    <button ng-click="queryTask(item)"
                                                            class="btn btn-xs pull-right"
                                                            style="margin-left: 5px; background-color: #2e6da4; color: white;">
                                                        <span class="glyphicon glyphicon-search"></span>Task详情
                                                    </button>

                                                </td>
                                            </tr>
                                            </tbody>
                                            <tfoot>
                                            <tr>
                                                <td colspan="9">
                                                    <ul style="margin: 0px; float: right;" uib-pagination
                                                        total-items="totalItems" ng-model="currentPage"
                                                        items-per-page="pageLength" max-size="10"
                                                        ng-change="pageChanged()" previous-text="&lsaquo;"
                                                        next-text="&rsaquo;"></ul>
                                                </td>
                                            </tr>
                                            </tfoot>
                                        </table>
                                    </div>
                                </div>
                            </div>


                            <div style="font-size:0.5em;">&nbsp;</div>
                            <div class="panel panel-info">
                                <div class="panel-heading">执行结果</div>
                                <div ng-if="taskVO.taskServerList != null">
                                    <!--style="margin-left: 20px;-->
                                    <span class="label label-danger" ng-show="taskVO.ansibleTaskDO.finalized ==false">
                                     <i class="fa fa-spin fa-spinner"></i>指令执行中...</span>
                                    <span class="label label-success"
                                          ng-show="taskVO.ansibleTaskDO.finalized ==true">指令执行完成</span>
                                    <span class="label"
                                          uib-popover-html="'执行的指令'"
                                          popover-trigger="'mouseenter'"
                                          style="background-color: black">{{taskVO.ansibleTaskDO.cmd}}</span>
                                    <span class="label"
                                          uib-popover-html="'服务器数量'"
                                          popover-trigger="'mouseenter'"
                                          style="background-color: #d78700">Total:{{taskVO.ansibleTaskDO.serverCnt}}</span>

                                    <input type="checkbox" ng-model="resultChoose.all" ng-click="chooseAllResult()"><b
                                        style="color: #00a8f3"> 所有结果</b>
                                    <input type="checkbox" ng-model="resultChoose.success" ng-click="chooseResult(0)"><b
                                        style="color: #00af00"> SUCCESS</b>
                                    <input type="checkbox" ng-model="resultChoose.failed" ng-click="chooseResult(1)"><b
                                        style="color: #b92c28"> FAILED</b>
                                </div>

                                <div class="form-group">
                                    <form class="form-inline" role="form" ng-if="taskVO.taskServerList != null">
                                        <table class="table" style="margin-top: 5px;">
                                            <tbody>
                                            <tr ng-repeat="taskServer in taskVO.taskServerList">
                                                <td class="col-md-12" ng-show="checkResultShow(taskServer)">
                                                    <div class="panel-heading" style="background-color: #2e6da4">
                                                    <span class="label label-default"
                                                          ng-if="taskServer.serverDO.envType == 0">{{taskServer.serverDO.serverName + "-" + taskServer.serverDO.serialNumber}}(保留)</span>
                                                        <span class="label label-info"
                                                              ng-if="taskServer.serverDO.envType == 1">{{taskServer.serverDO.serverName + "-" + taskServer.serverDO.serialNumber}}(dev)</span>
                                                        <span class="label label-success"
                                                              ng-if="taskServer.serverDO.envType == 2">{{taskServer.serverDO.serverName + "-" + taskServer.serverDO.serialNumber}}(daily)</span>
                                                        <span class="label label-warning"
                                                              ng-if="taskServer.serverDO.envType == 3">{{taskServer.serverDO.serverName + "-" + taskServer.serverDO.serialNumber}}(gray)</span>
                                                        <span class="label label-danger"
                                                              ng-if="taskServer.serverDO.envType == 4">{{taskServer.serverDO.serverName + "-" + taskServer.serverDO.serialNumber}}(prod)</span>
                                                        <span class="label label-primary"
                                                              ng-if="taskServer.serverDO.envType == 5">{{taskServer.serverDO.serverName + "-" + taskServer.serverDO.serialNumber}}(test)</span>
                                                        <span class="label label-primary"
                                                              ng-if="taskServer.serverDO.envType == 6">{{taskServer.serverDO.serverName + "-" + taskServer.serverDO.serialNumber}}(back)</span>

                                                        <span class="label label-info">{{taskServer.ip}}</span>
                                                        <span class="label label-success"
                                                              ng-if="taskServer.result == 'SUCCESS'">{{taskServer.result}}</span>
                                                        <span class="label label-danger"
                                                              ng-if="taskServer.result != 'SUCCESS'">{{taskServer.result}}</span>
                                                        <span class="label label-info"
                                                              ng-show="taskServer.returncode != null">{{taskServer.returncode}}</span>

                                                        <button ng-click="closeTaskServer(taskServer.serverId)"
                                                                class="btn btn-xs pull-right"
                                                                style="margin-left: 20px; background-color: #ff8700; color: white;">
                                                            <span class="glyphicon glyphicon-remove"></span>关闭
                                                        </button>
                                                    </div>
                                                    <div hljs hljs-source="taskServer.msg"></div>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>

                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </uib-tab>



            </uib-tabset>
        </div>
    </div>
    <!-- / main -->
</div>


<script type="text/ng-template" id="versionInfoModal">
    <div ng-include="'tpl/modal/ansible_version_info_modal.html'"></div>
</script>


<script type="text/ng-template" id="scriptInfoModal">
    <div ng-include="'tpl/modal/script_info_modal.html'"></div>
</script>


<script type="text/ng-template" id="serverInfo">
    <div ng-include="'tpl/modal/server_info_modal.html'"></div>
</script>

<script type="text/ng-template" id="serverpsInfo">
    <div ng-include="'tpl/modal/serverpg_modal.html'"></div>
</script>